﻿using DevExpress.XtraEditors;
using DevTeam;
using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace ConfExpert.Forms.Rapor.Kartela
{
    public partial class SablonSec : XPopupForm
    {
        public SablonSec()
        {
            InitializeComponent();
        }

        Image GetPhoto(int i)
        {
            if (dt.Rows.Count > 0)
                if (dt.Rows[i]["Photo"] != DBNull.Value)
                    return Image.FromStream(new MemoryStream((byte[])dt.Rows[i]["Photo"]));
                else
                    return null;
            else
                return null;
        }

        DataTable dt;
        private void SablonSec_Load(object sender, EventArgs e)
        {
            ShowOnlyFooter();
            FooterText = "Lütfen kullanmak istediğiniz şablona tıklayın";

            dt = ExecuteDataTable("GetKartelaSablon");
            pe1.Image = GetPhoto(0);
            pe2.Image = GetPhoto(1);
            pe3.Image = GetPhoto(2);
            pe4.Image = GetPhoto(3);
            pe5.Image = GetPhoto(2);
            pe6.Image = GetPhoto(3);

            pe1.ToolTip = "1";
            pe2.ToolTip = "2";
            pe3.ToolTip = "3";
            pe4.ToolTip = "4";
            pe5.ToolTip = "5";
            pe6.ToolTip = "6";

            //picture.Properties.SizeMode = PictureSizeMode.Stretch;

            pe1.Click += pe1_Click;
            pe2.Click += pe1_Click;
            pe3.Click += pe1_Click;
            pe4.Click += pe1_Click;
            pe5.Click += pe1_Click;
            pe6.Click += pe1_Click;
        }

        void pe1_Click(object sender, EventArgs e)
        {
            string PEName = ((PictureEdit)sender).Name;
            SablonTipi = PEName.Substring(2, 1).ToInt();
            this.DialogResult = DialogResult.OK;
        }

        public int SablonTipi { get; set; }
    }
}
